﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmallJob.Services.Code
{
    public class StringHanding
    {
        public static String Convert(String input)
        {
            string result = input;
            string convert = "ĂÂÀẰẦÁẮẤẢẲẨÃẴẪẠẶẬỄẼỂẺÉÊÈỀẾẸỆÔÒỒƠỜÓỐỚỎỔỞÕỖỠỌỘỢƯÚÙỨỪỦỬŨỮỤỰÌÍỈĨỊỲÝỶỸỴĐăâàằầáắấảẳẩãẵẫạặậễẽểẻéêèềếẹệôòồơờóốớỏổởõỗỡọộợưúùứừủửũữụựìíỉĩịỳýỷỹỵđ";
            string To = "AAAAAAAAAAAAAAAAAEEEEEEEEEEEOOOOOOOOOOOOOOOOOUUUUUUUUUUUIIIIIYYYYYDaaaaaaaaaaaaaaaaaeeeeeeeeeeeooooooooooooooooouuuuuuuuuuuiiiiiyyyyyd";
            for (int i = 0; i < To.Length; i++)
            {
                result = result.Replace(convert[i], To[i]);
            }
            return result;
        }
        public static bool HasSpecialCharacters(string s) {
            string special = " `~!@#$%^&*()-+={}[];:\'\"<,>?/\\|";
            for (int i = 0; i < special.Length; i++) {
                if (s.Contains(special[i]))
                    return true;
            }
                return false;
        }
        public static int CountContain(String text1, String text2)
        {
            int result = 0;
            string s1 = StringHanding.Convert(text1);
            string s2 = StringHanding.Convert(text2);
            char[] separator = { ' ' };
            string[] array1 = s1.Split(separator).Where(s => s != "").ToArray();
            foreach (var item in array1)
            {
                if (s2.Contains(item))
                    result++;
            }
            return result;
        }
        public static string ConvertUrl(string text) {
            var result = Convert(text).ToLower();
            result = result.Replace(" ", "-").Replace(":", "").Replace(",", "").Replace(".", "").Replace("+","");
            return result;
        }
        public static String CreateUrlProduct(int productID,string productTitle,string providerName) {
            string title = ConvertUrl(productTitle);
            string name = ConvertUrl(providerName);
            return "http://byhand.vn/" + name + "/" + title + "-" + productID + ".html";
        }
    }
}
